package com.ruoyi.system.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

@Configuration
public class CaptchaConfig {
    @Bean(name = "captchaProducer")
    public Producer captchaProducer() {
        DefaultKaptcha kaptcha = new DefaultKaptcha();
        kaptcha.setConfig(new Config(new Properties() {{
            put("kaptcha.textproducer.char.length",  "4");
            put("kaptcha.image.width",  "120");
            put("kaptcha.textproducer.font.color",  "blue");
        }}));
        return kaptcha;
    }

    @Bean(name = "captchaProducerMath")
    public Producer captchaProducerMath() {
        DefaultKaptcha kaptcha = new DefaultKaptcha();
        Properties props = new Properties();
        props.put("kaptcha.textproducer.char.string",  "1234567890");
        props.put("kaptcha.textproducer.math.expression",  "@+randomInt(1,10)=?");
        kaptcha.setConfig(new  Config(props));
        return kaptcha;
    }
}
